package com.warrior.controller;

import com.warrior.Exception.ProjectException;
import com.warrior.entity.ActivityEntity;
import com.warrior.entity.MatchDetailsEntity;
import com.warrior.service.ActivityService;
import com.warrior.service.MatchDetailsService;
import com.warrior.util.CModelAndView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Shawn on 2017/3/30.
 */
@Controller
@RequestMapping("/matchDetail")
public class MatchDetailsController {

    @Autowired
    private MatchDetailsService matchDetailsService;

    @Autowired
    private ActivityService activityService;


    @RequestMapping(value = "/details",method = RequestMethod.GET)
    public ModelAndView getMatchDetail(HttpServletRequest request, HttpServletResponse response,String activityId){
        ModelAndView mv  = new CModelAndView("/",request,response);
        ActivityEntity activityEntity = this.activityService.findActivityById(activityId);
        mv.addObject("activity",activityEntity);

        try {
            List<MatchDetailsEntity> matchDetailsEntities = this.matchDetailsService.findMatchDetailsByActivityId(activityId);
            mv.addObject("matchDetails",matchDetailsEntities);
        } catch (ProjectException e) {
            e.printStackTrace();
        }

        return mv;
    }


}
